{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get forces information in OUTCAR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create OutCar object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from vaspy.iter import OutCar\n",
    "\n",
    "outcar = OutCar('OUTCAR')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Iterate force info in OUTCAR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Only get force information in the first step here\n",
    "for f in outcar.iforces:\n",
    "    if f.step == 1:\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Force info item"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ForceItem(step=1, coordinates=[[1.78441, 0.85618, 2.29204], [0.16369, 0.85618, 4.58407], [0.97405, -0.5474, 0.0], [0.97405, -0.5474, 6.87611], [4.21548, -0.5474, 2.29204], [2.59476, -0.5474, 4.58407], [3.40512, -1.95098, 0.0], [3.40512, -1.95098, 6.87611], [6.64655, -1.95098, 2.29204], [5.02584, -1.95098, 4.58407], [5.83619, -3.35456, 0.0], [5.83619, -3.35456, 6.87611], [1.78441, 3.66334, 2.29204], [0.16369, 3.66334, 4.58407], [0.97405, 2.25976, 0.0], [0.97405, 2.25976, 6.87611], [4.21548, 2.25976, 2.29204], [2.59476, 2.25976, 4.58407], [3.40512, 0.85618, 0.0], [3.40512, 0.85618, 6.87611], [6.64655, 0.85618, 2.29204], [5.02584, 0.85618, 4.58407], [5.83619, -0.5474, 0.0], [5.83619, -0.5474, 6.87611], [1.78441, 6.4705, 2.29204], [0.16369, 6.4705, 4.58407], [0.97405, 5.06692, 0.0], [0.97405, 5.06692, 6.87611], [4.21548, 5.06692, 2.29204], [2.59476, 5.06692, 4.58407], [3.40512, 3.66334, 0.0], [3.40512, 3.66334, 6.87611], [6.64655, 3.66334, 2.29204], [5.02584, 3.66334, 4.58407], [5.83619, 2.25976, 0.0], [5.83619, 2.25976, 6.87611]], forces=[[-0.0, 0.0, 0.243298], [0.0, 0.0, -0.243458], [-0.0, 0.0, -0.103119], [0.0, -0.0, 0.103279], [-0.0, 0.0, 0.243298], [-0.0, 0.0, -0.243458], [-0.0, 0.0, -0.103119], [-0.0, -0.0, 0.103279], [-0.0, 0.0, 0.243298], [0.0, -0.0, -0.243458], [-0.0, 0.0, -0.103119], [-0.0, -0.0, 0.103279], [-0.0, 0.0, 0.243298], [0.0, 0.0, -0.243458], [-0.0, 0.0, -0.103119], [-0.0, -0.0, 0.103279], [-0.0, 0.0, 0.243298], [-0.0, 0.0, -0.243458], [-0.0, 0.0, -0.103119], [0.0, -0.0, 0.103279], [-0.0, 0.0, 0.243298], [-0.0, 0.0, -0.243458], [-0.0, 0.0, -0.103119], [0.0, -0.0, 0.103279], [-0.0, 0.0, 0.243298], [0.0, -0.0, -0.243458], [-0.0, 0.0, -0.103119], [0.0, 0.0, 0.103279], [-0.0, 0.0, 0.243298], [0.0, 0.0, -0.243458], [-0.0, 0.0, -0.103119], [0.0, 0.0, 0.103279], [-0.0, 0.0, 0.243298], [0.0, -0.0, -0.243458], [-0.0, 0.0, -0.103119], [0.0, 0.0, 0.103279]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Force info item includes 3 attributes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ionic step number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.step"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### current coordinates of atoms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[1.78441, 0.85618, 2.29204],\n",
       " [0.16369, 0.85618, 4.58407],\n",
       " [0.97405, -0.5474, 0.0],\n",
       " [0.97405, -0.5474, 6.87611],\n",
       " [4.21548, -0.5474, 2.29204],\n",
       " [2.59476, -0.5474, 4.58407],\n",
       " [3.40512, -1.95098, 0.0],\n",
       " [3.40512, -1.95098, 6.87611],\n",
       " [6.64655, -1.95098, 2.29204],\n",
       " [5.02584, -1.95098, 4.58407],\n",
       " [5.83619, -3.35456, 0.0],\n",
       " [5.83619, -3.35456, 6.87611],\n",
       " [1.78441, 3.66334, 2.29204],\n",
       " [0.16369, 3.66334, 4.58407],\n",
       " [0.97405, 2.25976, 0.0],\n",
       " [0.97405, 2.25976, 6.87611],\n",
       " [4.21548, 2.25976, 2.29204],\n",
       " [2.59476, 2.25976, 4.58407],\n",
       " [3.40512, 0.85618, 0.0],\n",
       " [3.40512, 0.85618, 6.87611],\n",
       " [6.64655, 0.85618, 2.29204],\n",
       " [5.02584, 0.85618, 4.58407],\n",
       " [5.83619, -0.5474, 0.0],\n",
       " [5.83619, -0.5474, 6.87611],\n",
       " [1.78441, 6.4705, 2.29204],\n",
       " [0.16369, 6.4705, 4.58407],\n",
       " [0.97405, 5.06692, 0.0],\n",
       " [0.97405, 5.06692, 6.87611],\n",
       " [4.21548, 5.06692, 2.29204],\n",
       " [2.59476, 5.06692, 4.58407],\n",
       " [3.40512, 3.66334, 0.0],\n",
       " [3.40512, 3.66334, 6.87611],\n",
       " [6.64655, 3.66334, 2.29204],\n",
       " [5.02584, 3.66334, 4.58407],\n",
       " [5.83619, 2.25976, 0.0],\n",
       " [5.83619, 2.25976, 6.87611]]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.coordinates"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### forces on all atoms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[-0.0, 0.0, 0.243298],\n",
       " [0.0, 0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [0.0, -0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [-0.0, 0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [-0.0, -0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [0.0, -0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [-0.0, -0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [0.0, 0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [-0.0, -0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [-0.0, 0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [0.0, -0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [-0.0, 0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [0.0, -0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [0.0, -0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [0.0, 0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [0.0, 0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [0.0, 0.0, 0.103279],\n",
       " [-0.0, 0.0, 0.243298],\n",
       " [0.0, -0.0, -0.243458],\n",
       " [-0.0, 0.0, -0.103119],\n",
       " [0.0, 0.0, 0.103279]]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.forces"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get the maximum force"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "natom, force = outcar.fmax(f.forces)  # atom number, force vector along x y z axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "natom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.0, 0.0, -0.243458]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "force"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
